
package Vistas;

import ConexionBD.UsuarioBd;
import ConexionBD.VehiculoBD;
import ConexionBD.mysql;
import Usuario.Usuario;
import Vehiculo.carro;
import com.itextpdf.text.*;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.ImageObserver;
import java.util.Date;
import java.util.Timer;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import java.io.FileNotFoundException;
import java.io.FileOutputStream; 
import com.itextpdf.text.pdf.PdfWriter;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import pdf.reporteCarro;


public class Gestionvehiculo extends javax.swing.JDialog {
       mysql conexion = new mysql();
       UsuarioBd BusarU = new UsuarioBd();
       VehiculoBD BuscaCarro = new VehiculoBD();
       Usuario  Nusuario;
       carro Carro;
       
    public Gestionvehiculo(String ci) {
        setTitle("Gestion Vehicular");
        initComponents();
        setVisible(true);
        setLocationRelativeTo(null);
        this.queDeseahacer.setEnabled(false);
        this.SeleccionStatus.setEnabled(false);
        this.opcionesvehiculares.setEnabled(false);
        FechaSistema();
              
     Nusuario = BusarU.ObtieneUsuario(conexion.getConexionLocal(), ci);
     
     try{
         
     boolean existe =  BuscaCarro.ExisteCarro(conexion.getConexionLocal(), ci); 
     if(existe){
     Carro  = BuscaCarro.ObtieneVehiculo(conexion.getConexionLocal(),ci);
     this.recibeModelo.setText(Carro.getModelo().toUpperCase()); 
     String Km = String.valueOf(Carro.getKilometrajeTotal());
     this.recibeKilometro.setText(Km);
     }
     else{
         JOptionPane.showMessageDialog(null, "El usuario:" + Nusuario.getNombre() + "No tiene ningun vehiculo registrado");
         }
     }catch(Exception e){
         JOptionPane.showMessageDialog(null, "Verifique la Informacion");
     }
     
     this.recibeNombre.setText(Nusuario.getNombre().toUpperCase() + "," + Nusuario.getApellido().toUpperCase() + "*-*" + "Gracias Por Crear Su Cuenta!!");
     
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        recibeNombre = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        recibeKilometro = new javax.swing.JLabel();
        recibeFecha = new javax.swing.JLabel();
        recibeModelo = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        queDeseahacer = new javax.swing.JLabel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jTabbedPane2 = new javax.swing.JTabbedPane();
        DatosVehiculos = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        GeneraReporte = new javax.swing.JButton();
        modificardatosUsuario = new javax.swing.JButton();
        SeleccionStatus = new javax.swing.JComboBox();
        mensajeImportanta = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        opcionesvehiculares = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Bienvenido", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, new java.awt.Color(216, 67, 67)));

        jLabel1.setText("Bienvenido:");

        jLabel2.setText("Vehiculo:");

        jLabel3.setText("Kilometros:");

        recibeNombre.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jLabel5.setText("Fecha Inicio:");

        recibeKilometro.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));

        recibeFecha.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));

        recibeModelo.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(recibeFecha, javax.swing.GroupLayout.PREFERRED_SIZE, 621, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(recibeKilometro, javax.swing.GroupLayout.PREFERRED_SIZE, 621, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(recibeNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 621, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addComponent(recibeModelo, javax.swing.GroupLayout.PREFERRED_SIZE, 621, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addGap(0, 21, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(recibeNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel2)
                    .addComponent(recibeModelo, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 15, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(recibeKilometro, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addComponent(recibeFecha, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED), "Opciones Adminstrativas", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, new java.awt.Color(72, 20, 20)));

        queDeseahacer.setText("Opciones Usuarioa:");

        jTabbedPane1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTabbedPane1MouseClicked(evt);
            }
        });

        jTabbedPane2.setBackground(new java.awt.Color(107, 137, 135));
        jTabbedPane2.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jTabbedPane1.addTab("Opciones:", jTabbedPane2);

        DatosVehiculos.setText("Adminstrar  Datos Vehicular");
        DatosVehiculos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DatosVehiculosActionPerformed(evt);
            }
        });
        jTabbedPane1.addTab("Datos Vehiculares", DatosVehiculos);

        jButton3.setText("Verificacion Actual de SENSORES");
        jTabbedPane1.addTab("Sensores", jButton3);

        GeneraReporte.setText("Generacion de Reportes");
        GeneraReporte.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                GeneraReporteActionPerformed(evt);
            }
        });
        jTabbedPane1.addTab("Reportes", GeneraReporte);

        modificardatosUsuario.setText("Modificar Datos Personales");
        modificardatosUsuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                modificardatosUsuarioActionPerformed(evt);
            }
        });
        jTabbedPane1.addTab("Modificar Datos Personales", modificardatosUsuario);

        SeleccionStatus.setFont(new java.awt.Font("Serif", 0, 15)); // NOI18N
        SeleccionStatus.setForeground(new java.awt.Color(140, 95, 95));
        SeleccionStatus.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "opciones:", "modificar", "eliminar", "buscar" }));
        SeleccionStatus.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED, null, new java.awt.Color(220, 109, 109), null, null));
        SeleccionStatus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SeleccionStatusActionPerformed(evt);
            }
        });

        mensajeImportanta.setFont(new java.awt.Font("SansSerif", 3, 15)); // NOI18N
        mensajeImportanta.setForeground(new java.awt.Color(141, 4, 4));

        jLabel4.setText("Opciones Vehiculo:");

        opcionesvehiculares.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "opciones:", "crear", "Buscar", "Eliminar", "Status" }));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(36, 36, 36)
                        .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 698, Short.MAX_VALUE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(26, 26, 26)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(opcionesvehiculares, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(queDeseahacer)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(SeleccionStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(mensajeImportanta, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1)
                .addGap(38, 38, 38)
                .addComponent(mensajeImportanta, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(queDeseahacer)
                    .addComponent(SeleccionStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(6, 6, 6)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(opcionesvehiculares, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jTabbedPane1.getAccessibleContext().setAccessibleName("Adminstracion de Usuario");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(25, 25, 25)
                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void modificardatosUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_modificardatosUsuarioActionPerformed
   
       String valor = (String)this.SeleccionStatus.getItemAt(this.SeleccionStatus.getSelectedIndex());
       
       if(valor.equals("opciones:")){
           
           this.mensajeImportanta.setText("Debe seleccionar Una de las Opciones en el JComboBox:");
       } 
       
       else if(!valor.equals("opciones:")){
           this.mensajeImportanta.setText("Gracias");
           AdministrarUsuario ventana = new AdministrarUsuario(valor,Nusuario.getCI());
           ventana.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
           ventana.setLocationRelativeTo(null);
           
       }
        // TODO add your handling code here:
    }//GEN-LAST:event_modificardatosUsuarioActionPerformed

    private void jTabbedPane1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTabbedPane1MouseClicked

        this.queDeseahacer.setEnabled(true);
        this.SeleccionStatus.setEnabled(true);
        this.opcionesvehiculares.setEnabled(false);
        // TODO add your handling code here:
    }//GEN-LAST:event_jTabbedPane1MouseClicked

    private void SeleccionStatusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SeleccionStatusActionPerformed
        // TODO add your handling code here:
        this.SeleccionStatus.setForeground(Color.LIGHT_GRAY);
    }//GEN-LAST:event_SeleccionStatusActionPerformed

    private void DatosVehiculosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DatosVehiculosActionPerformed
        
     this.opcionesvehiculares.setEnabled(true);
        
      String valor = (String)this.opcionesvehiculares.getItemAt(this.opcionesvehiculares.getSelectedIndex());
       
       if(valor.equals("opciones:")){
           
           this.mensajeImportanta.setText("Debe seleccionar Una de las Opciones en el JComboBox:");
       } 
       
       else if(!valor.equals("opciones")){
           
        this.mensajeImportanta.setText("Gracias");
        AdminstrarVehiculo ventana = new AdminstrarVehiculo(valor,Nusuario.getCI(),Nusuario.getNcarros());
        ventana.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        ventana.setLocationRelativeTo(null);
           
       }
        // TODO add your handling code here:
    }//GEN-LAST:event_DatosVehiculosActionPerformed

    private void GeneraReporteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_GeneraReporteActionPerformed
      
       reporteCarro reporte = new reporteCarro(Carro,Nusuario);;
               // TODO add your handling code here:
    }//GEN-LAST:event_GeneraReporteActionPerformed

    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton DatosVehiculos;
    private javax.swing.JButton GeneraReporte;
    private javax.swing.JComboBox SeleccionStatus;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTabbedPane jTabbedPane2;
    private javax.swing.JLabel mensajeImportanta;
    private javax.swing.JButton modificardatosUsuario;
    private javax.swing.JComboBox opcionesvehiculares;
    private javax.swing.JLabel queDeseahacer;
    private javax.swing.JLabel recibeFecha;
    private javax.swing.JLabel recibeKilometro;
    private javax.swing.JLabel recibeModelo;
    private javax.swing.JLabel recibeNombre;
    // End of variables declaration//GEN-END:variables

public final void FechaSistema(){
     
        java.util.Date utilDate = new java.util.Date(); //fecha actual
        long lnMilisegundos = utilDate.getTime();
        java.sql.Date sqlDate = new java.sql.Date(lnMilisegundos);
        java.sql.Time sqlTime = new java.sql.Time(lnMilisegundos);
        String fecha = String.valueOf(sqlDate);
        String hora = String.valueOf(sqlTime);
        this.recibeFecha.setText(fecha);
       // this.muestraHora.setText(hora);
 }


public boolean verificacambio(float kilometros){
    
    
    
    
    return true;
}


}
